<?php 
class DistrictController extends Controller{
	private $model;

	public function __init(){
		parent::__init();
		$this->model = K('District');
	}

	public function index(){
		$allData = $this->model->get_data();
		$allData= Data::tree($allData,'dname','did','pid');
		$this->assign('allData',$allData);

		$this->display();
	}


	public function add(){
		if(IS_POST){
		if($this->model->create()){
			$this->model->add_data();
			$this->success('添加成功',U('index'));
		}
		$this->error($this->model->error);
		}
		$this->display();
	}


	public function add_son(){
		if(IS_POST){
			if($this->model->create()){
				$this->model->add_data();
				$this->success('添加成功',U('index'));
			}
			$this->error($this->model->error);
		}

		$one_data = $this->model->find_data(array('did'=>Q('get.did',0,'intval')));
		$this->assign('one_data',$one_data);
		$this->display();
	}

	public function del(){

		if($this->model->del_data(Q('get.did',0,'intval'))){
			$this->success('删除成功');
		}else{
		$this->error($this->model->error);
		}
	}

	public function edit_cate(){
 		if (IS_POST) {
 			$this->model->update_data(array('did'=>Q('get.did',0,'intval')));
 			$this->success('修改成功',U('Index'));
 		}

 	$default = $this->model->find_data(Q('get.did'),0,'intval');
 	$this->assign('default',$default);



 	// 获得所有的分类
 	$cateData = $this->model->get_data();
 	$cateData= Data::tree($cateData,'dname','did','pid');

 	$this->assign('cateData',$cateData);
 	$this->display();
 	}


}






?>